package com.cloud.jucTest;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HashMapCurrentTest {
    public static void main(String[] args) {
        Map map = new HashMap<String, String>();
        ExecutorService executorService = Executors.newCachedThreadPool();

        CountDownLatch latch = new CountDownLatch(50);
        for (int i = 0; i < 50; ++i) {
            executorService.execute(() -> {
                try {
                    for (int j = 0; j < 50; ++j) {
                        map.put(UUID.randomUUID().toString(), "shuchuanbiao");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    latch.countDown();
                }
            });
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("the size of the map is " + map.size());
        executorService.shutdown();
    }
}
